package com.elloe.lesson;

/**
 * @author ElloeStudy(Sifa Zhang)
 * @create 2021-11-17 18:51
 * To: 真常应物，真常得性，常清常静，常清静矣
 */
public class Demo3 {
    // 求x的n次方
    public static long fun1(int x,int n){
        int result = 1;
        for (int i = 0; i < n; i++) {
            result = result * x;
        }
        return  result;
    }

    public static long fun2(int x,int n){
        // 基线条件
        if (n==0){
            return 1; // 任何数的0次方为1
        }
        return fun2(x, n-1)*x;
    }


    public static void main(String[] args) {
        int x = 2;
        int k = 10;
        long startTime = System.currentTimeMillis();
        System.out.println("fun2  -->"+fun2(x, k));
        long endTime = System.currentTimeMillis();
        System.out.println((endTime-startTime));
    }
}
